#获取账号信息
#输入：存储账号信息的文本地址
#输出：文本中的所有信息行
import time

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By


class LogOp:
    AccountData = None

    def AcquireAccountInfo(self,AccountPath="D:\python_for_git\learn_selenium\AcquireJingDongProductData\AccountInfo.txt"):
        with open(AccountPath,'r') as AccountFile:
            self.AccountData = AccountFile.readlines()

    # 使用账密登入京东
    def LogIn(self,driver):
        # 拆分账号密码
        # dataArry = self.AccountData[0].split(',')
        # accountName = dataArry[0]
        # password = dataArry[1]
        accountName = "Ytest350"
        password = "M+)$2kxQFS}Zuq8"
        # 进行登入操作
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div[1]/div[3]/div/ul[1]/li[3]/a[1]').click()# 进入登录页面
        time.sleep(2)
        driver.find_element(By.XPATH,'//*[@id="loginname"]').send_keys(accountName)   #输入账号
        time.sleep(2)
        driver.find_element(By.XPATH,'//*[@id="nloginpwd"]').send_keys(password)      #输入密码
        time.sleep(2)
        driver.find_element(By.XPATH,'#formlogin > div.item.item-fore5').click()      #点击登录按钮

    def LogOut(self,driver):
        actions = ActionChains(driver)
        element = driver.find_element(By.CSS_SELECTOR,'.nickname')
        sub_element = driver.find_element(By.CSS_SELECTOR,'.link-logout')
        actions.move_to_element(element).click(sub_element).perform()
